#include "stdafx.h"
#include "SomeContainterIterator.h"
#include "SomeContainer.h"
#include "IObject.h"

CSomeContainterIterator::CSomeContainterIterator(CSomeContainer* contaiter)
{
    CSomeContainer::Objects_mt::const_iterator begin = contaiter->m_map.begin();
    CSomeContainer::Objects_mt::const_iterator end = contaiter->m_map.end();
    for (; begin != end; begin++)
    {
        m_weakCopyMap.push_back(begin->second);
    }
    m_iterForward = m_weakCopyMap.begin();
    m_iterReverse = m_weakCopyMap.rbegin();
}

boost::shared_ptr<IObject> CSomeContainterIterator::Begin()
{
    if (!m_weakCopyMap.empty())
    {
        return *m_weakCopyMap.begin();
    }
    return boost::shared_ptr<IObject>();
}

boost::shared_ptr<IObject> CSomeContainterIterator::End()
{
    return boost::shared_ptr<IObject>();
}

boost::shared_ptr<IObject> CSomeContainterIterator::Next()
{
    if (++m_iterForward == m_weakCopyMap.end())
    {
        return End();
    }
    return *m_iterForward;
}

boost::shared_ptr<IObject> CSomeContainterIterator::Prev()
{
    if (m_iterForward == m_weakCopyMap.begin())
    {
        return Begin();
    }
    --m_iterForward;
    return *m_iterForward;
}